/**
 * 
 */
package com.lanswon.qzsmk.service.cardManageService.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.UnavailableSecurityManagerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lanswon.qzsmk.base.AccountContants;
import com.lanswon.qzsmk.base.AppContants;
import com.lanswon.qzsmk.base.BlackListContants;
import com.lanswon.qzsmk.base.CardContants;
import com.lanswon.qzsmk.base.DwzPage;
import com.lanswon.qzsmk.dao.AppKindMapper;
import com.lanswon.qzsmk.dao.AppOpenRegMapper;
import com.lanswon.qzsmk.dao.BlackListGenMapper;
import com.lanswon.qzsmk.dao.BlackListRcMapper;
import com.lanswon.qzsmk.dao.BusiParamMapper;
import com.lanswon.qzsmk.dao.BusinessMapper;
import com.lanswon.qzsmk.dao.CardControlMapper;
import com.lanswon.qzsmk.dao.CardDataMapper;
import com.lanswon.qzsmk.dao.CardManageMapper;
import com.lanswon.qzsmk.dao.CardProdunctDefinitionMapper;
import com.lanswon.qzsmk.dao.CardTypeMapper;
import com.lanswon.qzsmk.dao.CertMapper;
import com.lanswon.qzsmk.dao.CertificateMapper;
import com.lanswon.qzsmk.dao.ChangeCardMapper;
import com.lanswon.qzsmk.dao.FeeRulesMapper;
import com.lanswon.qzsmk.dao.NationMapper;
import com.lanswon.qzsmk.dao.PersonalMapper;
import com.lanswon.qzsmk.dao.SubaccountPersonalMapper;
import com.lanswon.qzsmk.dao.TransGlideMapper;
import com.lanswon.qzsmk.dao.TxnDtlMapper;
import com.lanswon.qzsmk.exception.ApplicationException;
import com.lanswon.qzsmk.exception.ErrorCode;
import com.lanswon.qzsmk.model.ActiveUser;
import com.lanswon.qzsmk.model.AppKind;
import com.lanswon.qzsmk.model.AppOpenReg;
import com.lanswon.qzsmk.model.BlackListGen;
import com.lanswon.qzsmk.model.BlackListRc;
import com.lanswon.qzsmk.model.Business;
import com.lanswon.qzsmk.model.CardControl;
import com.lanswon.qzsmk.model.CardData;
import com.lanswon.qzsmk.model.CardManage;
import com.lanswon.qzsmk.model.CardProdunctDefinition;
import com.lanswon.qzsmk.model.Cert;
import com.lanswon.qzsmk.model.ChangeCard;
import com.lanswon.qzsmk.model.FeeRules;
import com.lanswon.qzsmk.model.Personal;
import com.lanswon.qzsmk.model.SubaccountPersonal;
import com.lanswon.qzsmk.service.cardManageService.ChangeCardService;
import com.lanswon.qzsmk.util.SequenceNumberUtil;
import com.lanswon.qzsmk.vo.ChangeCardInfo;
import com.lanswon.qzsmk.vo.FeeRulesVo;
import com.lanswon.qzsmk.vo.SellCardVo;
import com.lanswon.qzsmk.vo.VoucherVo;

/**
 * @author sun
 *
 */
@Service
public class ChangeCardServiceImpl implements ChangeCardService {

	@Autowired
	ChangeCardMapper ccm;

	@Autowired
	CardProdunctDefinitionMapper cpdm;

	@Autowired
	CardTypeMapper ctm;

	@Autowired
	PersonalMapper pm;

	@Autowired
	CertificateMapper cm;

	@Autowired
	CardManageMapper cmm;

	@Autowired
	CertMapper cem;

	@Autowired
	CardControlMapper cacm;

	@Autowired
	CardDataMapper cdm;

	@Autowired
	BusinessMapper bm;

	@Autowired
	BusiParamMapper bpm;

	@Autowired
	BlackListGenMapper blgm;

	@Autowired
	BlackListRcMapper blrm;

	@Autowired
	AppOpenRegMapper aorm;
	
	@Autowired
	AppKindMapper akm;
	
	@Autowired
	SubaccountPersonalMapper spm;
	
	@Autowired
	FeeRulesMapper frsm;
	
	@Autowired
	TransGlideMapper tgm;
	
	@Autowired
	TxnDtlMapper tdm;
	
	@Autowired
	NationMapper nationMapper;

	@Override
	public DwzPage<ChangeCardInfo> queryChangeCard(ChangeCardInfo cc) {
	

		cc.setCardTypeCode(CardContants.CARD_TYPE_ANONYMOUS);
		cc.setCardStatus(CardContants.CARD_STATE_NORMAL);
		List<ChangeCard> list = ccm.queryChangeCard(cc);
		List<ChangeCardInfo> l = new ArrayList<>();
		for (ChangeCard c1 : list) {
			ChangeCardInfo c2 = new ChangeCardInfo();
			c2.setCardPName(cpdm.queryCardPCode(c1.getCardpCode())
					.getCardpName());
			c2.setCardStatusName(CardContants.getCardStatusNameByCode(cc
					.getCardStatus()));
			c2.setCardTypeName(ctm.queryCardTypeByCode(c1.getCardTypecode())
					.getCardTypeName());
			if (StringUtils.isNotEmpty(c1.getPaperNo())
					&& StringUtils.isNotEmpty(c1.getPaperType())
					&& StringUtils.isNotEmpty(c1.getCustomerName())) {
				c2.setPaperNo(c1.getPaperNo());
				c2.setPaperTypeName(cm
						.queryCertificateByCode(c1.getPaperType())
						.getCertificatesName());
				c2.setCustomerName(c1.getCustomerName());
			}

			c2.setCitizenCardNo(c1.getCitizenCardNo());
			l.add(c2);

		}
		int totalCount = ccm.queryChangeCardCount(cc);

		DwzPage<ChangeCardInfo> dp = new DwzPage<ChangeCardInfo>(
				cc.getCurrentPage(), cc.getNumPerPage(), totalCount);

		dp.setList(l);

		return dp;
	}

	@Override
	public Map<String, Map<String, Object>> queryPersonalByPaperNo(
			ChangeCardInfo cc) {

		Map<String, Map<String, Object>> mm = new HashMap<>();

		CardProdunctDefinition cpd = cpdm.queryCardPCodeByCardProductName(cc
				.getCardPName());// 卡产品定义
		String cardPCode = cpd.getCardpCode();// 卡产品代码
		String cardValidTime = cpd.getCardValidTime().toString();// 卡的质保期

		String cardTypeCode = ctm.queryCardTypeByCardTypeName(
				cc.getCardTypeName()).getCardTypeCode();// 卡类型代码

		Date now = new Date();// 当前时间
		int changeCardDays = bpm.queryBusiParamByCardPCode(cardPCode)
				.getChcReleaseDays();
		Calendar c = Calendar.getInstance();
		c.setTime(now);
		c.add(Calendar.DAY_OF_MONTH, changeCardDays);// 今天+n天----不可读的领卡日期
		if (CardContants.CARD_TYPE_ANONYMOUS.equals(cardTypeCode)) {// 不记名卡
			Map<String, Object> map = new HashMap<>();

			cc.setCardQualityAssurance(cardValidTime);
			cc.setChangeCardDate(now);

			if (CardContants.CARD_IS_READ.equals(cc.getIsRead())) {
				cc.setGetCardDate(now);// 可读，领卡时间为当前时间
				/*
				 * map.put("CardIsRead", cc);//可读不记名卡 mm.put("Anonymous_Card",
				 * map);
				 */
			} else if (CardContants.CARD_NO_READ.equals(cc.getIsRead())) {
				cc.setGetCardDate(c.getTime());
			}
			map.put("Card", cc);// 不可读不记名卡
			mm.put("Anonymous_Card", map);

		} else if (CardContants.CARD_TYPE_REGISTERED.equals(cardTypeCode)
				|| CardContants.CARD_TYPE_STANDARD.equals(cardTypeCode)) {// 记名卡
			Map<String, Object> map = new HashMap<>();
			Personal p = pm.queryPersonalByPaperNo(
					cm.queryCertificateByName(cc.getPaperTypeName())
							.getCertificateType(), cc.getPaperNo());
			p.setCardTypeName(cc.getCardTypeName());
			p.setCardQualityAssurance(cardValidTime);
			p.setNationality(nationMapper.queryNationByCode(p.getNationality()).getNationname());
			p.setChangeCardDate(now);
			p.setIsRead(cc.getIsRead());
			if (CardContants.CARD_IS_READ.equals(cc.getIsRead())) {
				p.setGetCardDate(new Date());// 可读，领卡时间为当前时间
				/*
				 * map.put("CardIsRead", p); mm.put("Registered_Card", map);
				 */
			} else if (CardContants.CARD_NO_READ.equals(cc.getIsRead())) {
				p.setGetCardDate(c.getTime());
			}
			map.put("Card", p);
			mm.put("Registered_Card", map);
		}

		return mm;
	}

	@Transactional(rollbackFor=Exception.class)
	@Override
	public Map<String, Object> commitChangeCardInfo(ChangeCardInfo cci) throws ApplicationException {
		ActiveUser activeUser = null;
		try {
			activeUser = (ActiveUser) SecurityUtils.getSubject().getSession().getAttribute("activeUser");

		} catch (UnavailableSecurityManagerException e) {
			e.printStackTrace();
			activeUser = new ActiveUser();
			activeUser.setUserName("用户");
			activeUser.setLoginName("用户");
			activeUser.setBranchName("互联网端");
			activeUser.setBranchNo("99999999");
			activeUser.setUserNo(99999999);
			activeUser.setUserId(99999999);
		}
		
		if(activeUser == null){
			activeUser = new ActiveUser();
			activeUser.setUserName("用户");
			activeUser.setLoginName("用户");
			activeUser.setBranchName("互联网端");
			activeUser.setBranchNo("99999999");
			activeUser.setUserNo(99999999);
			activeUser.setUserId(99999999);
		}
		String cardTypeCode = ctm.queryCardTypeByCardTypeName(
				cci.getCardTypeName()).getCardTypeCode();// 卡类型代码
		
		Date now = new Date();

		CardManage c = new CardManage();
		c.setProcessId(UUID.randomUUID().toString().replace("-", ""));
		c.setApplyBranch(activeUser.getBranchName());
		c.setApplyBranchNo(activeUser.getBranchNo());
		c.setApplyDate(now);
		c.setApplyTellerNo(activeUser.getUserNo().toString());
		c.setApplyWay(CardContants.CLAIM_METHOD_SPORADIC);
		c.setCitizenCardNo(cci.getCitizenCardNo());
//		 c.setProcessCode(CardContants.CARD_PROC_CANCEL);
		 c.setProcessName("换卡-原卡注销");
		cmm.insert(c);

		// 更新原卡信息
		CardControl cc = cacm.queryCardControlByCitizenCardNo(cci
				.getCitizenCardNo());
		cc.setCardPosition(CardContants.CARD_POSITION_COUNTER_EMPLOYEE);// 卡位置--柜员
		cc.setCardStatus(CardContants.CARD_STATE_CANCELLATION_HAS_CARD);// 卡状态--注销
		cc.setLogoutDate(now);// 注销日期
		cc.setLastDate(now);// 最后修改时间
		cc.setLastOperator(activeUser.getUserNo().toString());// 最后一次操作员
		cc.setBlacklistFlag(CardContants.BLACKLIST_FLAG_INNER);// 黑名单标识-拉黑
		cc.setCurrProcId(c.getProcessId());
		cc.setIsRead(cc.getIsRead());
		cc.setClaimStatus(CardContants.CLAIM_STATUS_CANCEL);
		cc.setChangeCardDate(cci.getChangeCardDate());// 换卡日期
		cacm.updateCardControl(cc);

		// 查询老卡
		CardData ca = cdm.queryCardDataByCitizenCardNo(cci.getCitizenCardNo());

		Cert cert = new Cert();
		cert.setCertNo(SequenceNumberUtil.generatorCertNo());
		cert.setCertType(CardContants.BACK_CARD_REGISTRATION);
		cert.setCardpCode(ca.getCardpCode());
		cert.setCardTypecode(ca.getCardTypecode());

		if (CardContants.CARD_TYPE_REGISTERED.equals(cardTypeCode)
				|| CardContants.CARD_TYPE_STANDARD.equals(cardTypeCode)) {
			cert.setName(cci.getCustomerName());
			cert.setPaperNo(cci.getPaperNo());
			cert.setPaperType(cm.queryCertificateByName(cci.getPaperTypeName())
					.getCertificateType());
		}
		cert.setBranch(activeUser.getBranchName());
		cert.setBranchNo(activeUser.getBranchNo());
		cert.setAgentName(cci.getAgentName());
		cert.setAgentPaperNo(cci.getAgentPaperNo());
		cert.setAgentPapertype(cci.getAgentPapertype());
		cert.setCardControlId(cc.getCardControlId());
		cert.setCrtDate(now);
		cert.setCrtOperator(activeUser.getUserNo().toString());
		cert.setLastOperator(activeUser.getUserNo().toString());
		cert.setLastDate(now);
		cert.setData("换卡注销");
		cert.setTransCode("换卡注销");
		
		cem.insert(cert);

		Business bu = new Business();
		if (CardContants.CARD_TYPE_REGISTERED.equals(cardTypeCode)) {
			bu.setCustomerNo(ca.getCustomerNo());
		}
		bu.setBusinessNo(SequenceNumberUtil.generatorBusinessNo());
		bu.setCardControlId(cc.getCardControlId());
		bu.setTransCode("交易代码");
		bu.setAgentName(cci.getAgentName());
		bu.setAgentPaperNo(cci.getAgentPaperNo());
		bu.setAgentPapertype(cci.getAgentPapertype());
		bu.setAgentPhone(cci.getAgentPhone());
		bu.setBusiNum(1);
		bu.setTellerNo(activeUser.getUserNo().toString());
		bu.setTransDate(now);// 交易日期
		bu.setSeqStatus(CardContants.LSZT_NORMAL);
		bu.setRemark(cci.getDesc());
		bu.setCertNo(cert.getCertNo());
		bm.insert(bu);

		c.setCertNo(cert.getCertNo());
		c.setBusinessNo(bu.getBusinessNo());
		cmm.update(c);
		
		
		cert.setBusinessNo(bu.getBusinessNo());
		cem.update(cert);

		// 新数据
		CardData cdata = ca;
		cdata.setCardDataId(null);
		cdata.setCitizenCardNo(null);
		cdata.setChcOriCitizenNo(cci.getCitizenCardNo());
		cdm.insert(cdata);
		//
		//
		
		//
		//
		Calendar ccc = Calendar.getInstance();
		ccc.setTime(now);
		ccc.add(Calendar.DAY_OF_MONTH, bpm.queryBusiParamByCardPCode(ca.getCardpCode()).getReleaseDays());// 今天+n天===预计领卡日期

		
		CardControl co = new CardControl();
		co.setCardPosition(CardContants.CARD_POSITION_COUNTER_EMPLOYEE);// 卡位置--柜员
		co.setCardStatus(CardContants.CARD_STATE_DISABLED);// 卡状态--注销
		// co.setLogoutDate(new Date());// 注销日期
		co.setLastDate(now);// 最后修改时间
		co.setLastOperator(activeUser.getUserNo().toString());// 最后一次操作员
		co.setBlacklistFlag(CardContants.BLACKLIST_FLAG_NORMAL);// 黑名单标识-正常
        
		co.setIsRead(cc.getIsRead());
		co.setApplyDate(ccc.getTime());// 申领日期
		co.setCardDataId(cdata.getCardDataId());
		co.setApplyType(CardContants.APPLY_TYPE_CHANGE);
		// co.setDmgFlag(dmgFlag);
		co.setChangeCardDate(cci.getChangeCardDate());// 换卡日期
		co.setClaimStatus(CardContants.CLAIM_STATUS_CHANGE_CARD_APPLICATION);
		co.setReleaseDate(cci.getGetCardDate());
		cacm.insert(co);
		//
		//
		 Cert ce = new Cert();
		 ce.setCertNo(SequenceNumberUtil.generatorCertNo());
		 ce.setCertType(CardContants.CARD_CHANGE_APPLY);
		 ce.setCardpCode(ca.getCardpCode());
		 ce.setCardTypecode(ca.getCardTypecode());
		 ce.setCardControlId(co.getCardControlId());
		 if(CardContants.CARD_TYPE_REGISTERED.equals(cardTypeCode)){
		 ce.setName(cci.getCustomerName());
		 ce.setPaperNo(cci.getPaperNo());
		 ce.setPaperType(cm.queryCertificateByName(cci.getPaperTypeName()).getCertificateType());
		 }
		 ce.setBranch(activeUser.getBranchName());
		 ce.setBranchNo(activeUser.getBranchNo());
		 ce.setCrtOperator(String.valueOf(activeUser.getUserNo()));
		 ce.setAgentName(cci.getAgentName());
		 ce.setAgentPaperNo(cci.getAgentPaperNo());
		 ce.setAgentPapertype(cci.getAgentPapertype());
		 ce.setCrtDate(new Date());
		 ce.setCrtOperator(activeUser.getUserNo().toString());
		 ce.setLastDate(new Date());
		 ce.setLastOperator(activeUser.getUserNo().toString());
		
		
		 Business b = new Business();
		 if(CardContants.CARD_TYPE_REGISTERED.equals(cardTypeCode)){
		 b.setCustomerNo(ca.getCustomerNo());
		 }
		 b.setBusinessNo(SequenceNumberUtil.generatorBusinessNo());
		 b.setCardControlId(co.getCardControlId());
		 b.setTransCode("交易代码");
		 b.setAgentName(cci.getAgentName());
		 b.setAgentPaperNo(cci.getAgentPaperNo());
		 b.setAgentPapertype(cci.getAgentPapertype());
		 b.setAgentPhone(cci.getAgentPhone());
		 b.setBusiNum(1);
		 b.setTellerNo(activeUser.getUserNo().toString());
		 b.setTransDate(new Date());// 交易日期
		 b.setSeqStatus(CardContants.LSZT_NORMAL);
		 b.setRemark(cci.getDesc());
		 b.setCertNo(ce.getCertNo());
		 bm.insert(b);

		ce.setBusinessNo(b.getBusinessNo());
		String str = "{\"title\":\""+"换卡登记凭证"+"\",\"type\":\""+"changeCardRegister"+"\",\"certNo\":\""+cert.getCertNo()
		+"\",\"busType\":\""+CardContants.getCertTypeNameByCode(cert.getCertType())+"\",\"cardType\":\""+cert.getCardTypecode()
		+"\",\"citizenCardNo\":\""+cci.getCitizenCardNo()+"\",\"net\":\""+activeUser.getBranchName()+"\",\"operator\":\""
		+activeUser.getUserNo().toString()+"\",\"date\":\""+DateFormatUtils.format(new Date(), "yyyy-MM-dd")+"\"}";
		 ce.setData(str);
		 ce.setTransCode("换卡登记");
		 cem.insert(ce);
		 
		 
		 CardManage c1 = new CardManage();
			c1.setProcessId(UUID.randomUUID().toString().replace("-", ""));
			c1.setApplyBranch(activeUser.getBranchName());
			c1.setApplyBranchNo(activeUser.getBranchNo());
			c1.setApplyDate(now);
			c1.setApplyTellerNo(activeUser.getUserNo().toString());
			c1.setBusinessNo(b.getBusinessNo());
			c1.setCertNo(ce.getCertNo());
			c1.setApplyWay(CardContants.CLAIM_METHOD_SPORADIC);
			c1.setCardpCode(ca.getCardpCode());
			// cm.setCardSeqNo(cardSeqNo);
			// cm.setCitizenCardNo(citizenCardNo);
			// c1.setProcessCode(CardContants.CARD_PROC_CHANGE_CARD_APPLICATION);
			 c1.setProcessName("换卡-新卡申领");
			cmm.insert(c1);
			
			co.setCurrProcId(c1.getProcessId());
			cacm.updateCardControl(co);
		 
		 List<AppOpenReg> aors = aorm.queryAppOpenRegByCitizenCardNo(cci.getCitizenCardNo(),AppContants.APP_STATUS_OPEN);
			for(AppOpenReg aor:aors){
				aor.setStopDate(now);//停用日期
				aor.setLastDate(now);
				aor.setIsValid(AccountContants.IS_DEPOSIT_YES);
				aor.setAppStatus(AppContants.APP_STATUS_CLOSE);//关闭应用
				aor.setLastOperator(activeUser.getUserNo().toString());
				aor.setRemark(AppContants.APP_STATUS_CLOSE_CHANGECARD);
				aorm.update(aor);
				AppKind ak = akm.queryAppKindByTypeCode(Integer.valueOf(aor.getAppType()));
				List<SubaccountPersonal> sps = spm.querySubaccountPersonalByAppFlag(ak.getAppFlag(), cci.getCitizenCardNo());
				
				for(SubaccountPersonal sp:sps){
					sp.setFreezeStatus(AccountContants.FREEZE_STATUS_WHOLE);
					sp.setFreezeDate(now);
					sp.setFreezeAmount(sp.getTotalBalance());
					sp.setAccountStatus(AccountContants.ACCOUNT_STATUS_FROZEN);
					spm.update(sp);
				}
			}
		// 黑名单
		BlackListGen bb = blgm.queryBlackListGenBycitizenCardNo(cci
				.getCitizenCardNo());
		if (bb == null) {
			bb = new BlackListGen();
			bb.setCitizenCardNo(cci.getCitizenCardNo());
			bb.setCityCode(CardContants.CITY_CODE);
			// bb.setAppType(appType);//置黑应用类型
			// bb.setChipsInno(chipsInno);//接触卡内号
			// bb.setChipsLessInno(chipsLessInno);//非接卡内号
			// bb.setChipsLessNo(chipsLessNo);//非接芯片号
			// bb.setChipsNo(chipsNo);//接触芯片号
			bb.setBlCount(1);// 进黑名单次数
			bb.setBlReCount(0);// 解除黑名单次数
			bb.setBlReason(BlackListContants.BL_REASON_CHANGE_CARD_CANCELLATION);
			// bb.setBlReReason(blReReason);//解除黑名单原因
			bb.setLastBlRcDate(new Date());// 最后更新日期
			// bb.setCriticalLevel(criticalLevel);//严重级别 0-9, 严重级别由低至高.
			bb.setCurStatus(BlackListContants.BL_CUR_STATUS_TAKE_EFFECT);// 当前状态
			bb.setAvailDate(new Date());// 生效日期
			// bb.setRelieveDate(relieveDate);//解除日期
			bb.setBlackMode(BlackListContants.BL_BLACK_MODE_SYSTEM);// 置黑方式
			bb.setReleaseSys(BlackListContants.BL_PUBLISHING_SYSTEM_LIST_ALl);// 发布系统列表
			blgm.insert(bb);

		} else {
			bb.setBlCount(bb.getBlCount() + 1);
			bb.setBlReason(BlackListContants.BL_REASON_CHANGE_CARD_CANCELLATION);
			bb.setLastBlRcDate(new Date());// 最后更新日期
			bb.setAvailDate(new Date());// 生效日期
			bb.setCurStatus(BlackListContants.BL_CUR_STATUS_TAKE_EFFECT);// 当前状态
			bb.setBlackMode(BlackListContants.BL_BLACK_MODE_SYSTEM);// 置黑方式
			bb.setReleaseSys(BlackListContants.BL_PUBLISHING_SYSTEM_LIST_ALl);// 发布系统列表

			blgm.update(bb);
		}

		// 黑名单记录表
		BlackListRc blr = new BlackListRc();
		// blr.setAppType(appType);//置黑应用类型
		blr.setCitizenCardNo(cci.getCitizenCardNo());// 市民卡号
		blr.setRegisterType(BlackListContants.BL_CUR_STATUS_TAKE_EFFECT);// 登记类型
																			// 1.生效
																			// 2.解除
		blr.setAvailDate(new Date());// 生效日期
		// blr.setRelieveDate(relieveDate);//解除日期
		blr.setBlackMode(BlackListContants.BL_BLACK_MODE_SYSTEM);// 置黑方式 0-系统;
																	// 1-手工
		blr.setBlReason(BlackListContants.BL_REASON_CHANGE_CARD_CANCELLATION);// 进黑名单原因
		// blr.setBlReReason(blReReason);//解除黑名单原因
		// blr.setCriticalLevel(criticalLevel);//严重级别 0-9, 严重级别由低至高.
		blr.setBlSource(BlackListContants.BL_SOURCE_ALL);// 黑名单来源
		// blr.setReleaseSys(releaseSys);//下发系统
		// blr.setTransCode(transCode);//交易代码
		blr.setBusinessNo(bu.getBusinessNo());// 综合业务流水号
		// blr.setDoubtTrNo(doubtTrNo);/可疑交易流水号
		// blr.setssLockTrNo(lockTrNo);//锁卡交易流水号

		blrm.insert(blr);



		Map<String, Object> map = new HashMap<>();
		if (CardContants.CARD_IS_READ.equals(cci.getIsRead())) {// 可读，
			if(CardContants.SCENE_SEND_CARD_IS.equals(cci.getSceneSendCard())){//当场发卡 返回写卡页面所需显示的信息
				SellCardVo scv = new SellCardVo();
				
				scv.setCardPCodeName(cpdm.queryCardPCode(ca.getCardpCode()).getCardpName());
				scv.setOldCitizenBalance(cci.getCardBalance());
				scv.setOldCitizenCardNo(cci.getCitizenCardNo());
				scv.setCustomerName(cci.getCustomerName());
				scv.setPaperNo(cci.getPaperNo());
				scv.setPaperTypeName(cci.getPaperTypeName());
				scv.setCardTypeName(cci.getCardTypeName());
				List<AppOpenReg> la = aorm.queryAppOpenRegByRemark(scv.getOldCitizenCardNo(),AppContants.APP_STATUS_CLOSE_CHANGECARD);

				List<String> ls = new ArrayList<>();
				for(AppOpenReg aor :la){
					ls.add(aor.getAppType());
				}
				scv.setAppCodes(ls);
				scv.setBlackFlagName(BlackListContants.getBlackStatus(bb.getCurStatus()));
				
				scv.setBlackFlagReason(BlackListContants.getBlackReason(bb.getBlReason()));
				map.put(CardContants.CARD_IS_READ, scv);

			}else if(CardContants.SCENE_SEND_CARD_NO.equals(cci.getSceneSendCard())){//不当场返回换卡申请凭证
				VoucherVo vv = new VoucherVo();
				vv.setCertNo(ce.getCertNo());
				vv.setBusinessTypeName(CardContants.getCertTypeNameByCode(ce.getCertType()));
				vv.setCardType(ca.getCardTypecode());
				vv.setOldCitizenCardNo(cci.getCitizenCardNo());
				vv.setExpectCardDate(new Date());
				vv.setDate(DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
				vv.setOperator(activeUser.getUserNo().toString());
				vv.setNet(activeUser.getBranchName());
				
				map.put(CardContants.CARD_IS_READ, vv);
				
			}
			
			
		} else if (CardContants.CARD_NO_READ.equals(cci.getIsRead())) {
			if(CardContants.SCENE_SEND_CARD_IS.equals(cci.getSceneSendCard())){//说明卡面清晰 当场发卡 返回写卡页面所需显示的信息
				SellCardVo scv = new SellCardVo();
				
				scv.setCardPCodeName(cpdm.queryCardPCode(ca.getCardpCode()).getCardpName());
//				scv.setOldCitizenBalance(cci.getCardBalance());
				scv.setOldCitizenCardNo(cci.getCitizenCardNo());
				scv.setCustomerName(cci.getCustomerName());
				scv.setPaperNo(cci.getPaperNo());
				scv.setPaperTypeName(cci.getPaperTypeName());
				scv.setCardTypeName(cci.getCardTypeName());
				List<AppOpenReg> la = aorm.queryAppOpenRegByRemark(scv.getOldCitizenCardNo(),AppContants.APP_STATUS_CLOSE_CHANGECARD);

				List<String> ls = new ArrayList<>();
				for(AppOpenReg aor :la){
					ls.add(aor.getAppType());
				}
				scv.setAppCodes(ls);
				scv.setBlackFlagName(BlackListContants.getBlackStatus(bb.getCurStatus()));
				
				scv.setBlackFlagReason(BlackListContants.getBlackReason(bb.getBlReason()));
				map.put(CardContants.CARD_NO_READ, scv);

				
				
			}else if(CardContants.SCENE_SEND_CARD_NO.equals(cci.getSceneSendCard())){//不当场返回换卡申请凭证
				VoucherVo vv = new VoucherVo();
				vv.setCertNo(ce.getCertNo());
				vv.setBusinessTypeName(CardContants.getCertTypeNameByCode(ce.getCertType()));
				vv.setCardType(ca.getCardTypecode());
				vv.setOldCitizenCardNo(cci.getCitizenCardNo());
				vv.setExpectCardDate(cci.getGetCardDate());
				vv.setDate(DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
				vv.setOperator(activeUser.getUserNo().toString());
				vv.setNet(activeUser.getBranchName());
				map.put(CardContants.CARD_NO_READ, vv);
			}
			

		}
		return map;

	}

}
